package test3;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.text.ParseException;

public class demo5 {

	public static void main(String[] args) throws ParseException {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd  HH:mm:ss");

		Date date = new Date();

		// 格式化date-----把日期转换成字符串
		String str = sdf.format(date);
		System.out.println(str);

		// 解析-------把字符串转换成日期
		String d = "1992/25/12  11:12:10";
		Date date2 = sdf.parse(d);
		System.out.println(date2);
	}

}

/*
 * public static void main(String[] args) { String dStr = "2014.12.12-08:23:21";
 * Date d = null; SimpleDateFormat sdf = new
 * SimpleDateFormat("yyyy.MM.dd-HH:mm:ss"); try { d = sdf.parse(dStr); } catch
 * (ParseException pe) { System.out.println(pe.getMessage()); }
 * System.out.println(d); System.out.println(d.getTime());
 * 
 * }
 */
